package com.luojing.springcloud.service;

import java.util.HashSet;
import java.util.Set;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author luojing
 * @create 2018/10/18 2:01 PM
 **/
@Service
public class UserDetailServiceImpl implements UserDetailsService {

  @Override
  public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
    Set<GrantedAuthority> grantedAuthoritySet = new HashSet<>();
    grantedAuthoritySet.add(new SimpleGrantedAuthority("query1"));

    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    return new User("admin",passwordEncoder.encode("123456"),grantedAuthoritySet);
  }
}
